﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Orleans.Configuration;
using Orleans.Hosting;
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Orleans;
using System.Threading;

namespace OrleansTest
{
    class Program
    {
        static void Main(string[] args)
        {
            StartServer();
            do
            {
                Thread.Sleep(100);
            }
            while (Console.ReadLine() != "exit");
        }

        static void StartServer()
        {
            Console.WriteLine("正在启动服务...");
            new HostBuilder()
                .UseOrleans(builder =>
                {
                    builder
                        .UseLocalhostClustering(999)
                        .Configure<ClusterOptions>(options =>
                        {
                            options.ClusterId = "dev";
                            options.ServiceId = "GameCenter";
                        })
                        .Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
                        .ConfigureApplicationParts(parts =>
                        {
                            parts.AddApplicationPart(typeof(HelloGrain).Assembly).WithReferences();
                        });
                })
                .ConfigureServices(services =>
                {
                    services.Configure<ConsoleLifetimeOptions>(options =>
                    {
                        options.SuppressStatusMessages = true;
                    });
                })
                .ConfigureLogging(builder =>
                {
                    //builder.SetMinimumLevel(LogLevel.Warning);
                    builder.AddConsole();
                })
                .RunConsoleAsync().Wait();

            Console.WriteLine("服务启动完毕.");
        }

    }
}
